package no.ffi.gismoidm.pubsub;
// Command-line program to create and submit publications to a Message Router

import java.util.Collections;
import no.ffi.gismoidm.attrex.BooleanOperand;
import no.ffi.gismoidm.attrex.Parser;
import no.ffi.tpm.crypto.CryptoOperations;


public class TestSendPublications {
    public static void main(String[] args) throws Exception {
        PubSubClientProxy proxy;
        // Arg 1: Message string (Pub payload)
        String message = args[0];
        // Arg 2: Topic of the message
        String topic = args[1];
        // Arg 3: Subscriber requirement
        String subReq = args[2];
        // Arg 4: Optional configuration file
        if (args.length > 3)
            proxy = new PubSubClientProxy(args[4]);
        else
            proxy = new PubSubClientProxy("/home/anders/config/AndersFongen.properties");

        BooleanOperand sr = Parser.parse(subReq);
        CryptoOperations crOp = proxy.getCryptoOperations();
        Publication pub = new Publication(message, Collections.singletonList(topic), sr, crOp);
        System.out.println(pub);
        System.out.println(crOp.getISrequest());
        proxy.sendPublication(pub);
        Thread.sleep(5000);
    }
    

}
